import request from '@/utils/request';
import type { IPageQuery } from '@/interfaces/global';

export interface IAddInspectionTask {
  archiveTypeId?: number;
  attItemsList?: AttItemsList[];
  attOriginal?: AttOriginal;
  detectionType?: number;
  name?: string;
  status?: number;
  templateId?: number;
}
export interface AttItemsList {
  fileSize: number;
  fileUrl: string;
  level: number;
  status: boolean;
}

export interface AttOriginal {
  level: number;
  realFileList: RealFileList[];
  status: boolean;
}

export interface RealFileList {
  fileName: string;
  filePath: string;
  fileSize: number;
  fileUrl: string;
}
// 新增检测任务
export function addInspectionTask(data: IAddInspectionTask) {
  return request({
    url: `/archive-detection-job/`,
    method: 'post',
    data
  });
}
// 通过id编辑检测任务
export interface IEditInspectionTask extends IAddInspectionTask {
  id: number;
}
export function editInspectionTask(data: IEditInspectionTask) {
  return request({
    url: '/archive-detection-job/',
    method: 'put',
    data
  });
}

// 分页查询检测任务
export interface IfetchDetectionListByTaskParams {
  archiveTypeId?: number;
  createTime?: string;
  detectionType?: number;
  endTime?: string;
  id?: number;
  jobNo?: string;
  name?: string;
  operator?: number;
  operatorName: string;
  operatorTime?: string;
  startTime?: string;
  status?: number;
  templateId?: number;
}
export function fetchDetectionListByTask(data: IPageQuery<IfetchDetectionListByTaskParams>) {
  return request({
    url: `/archive-detection-job/page/`,
    method: 'post',
    data
  });
}
/* 查看检测报告 */
export function viewTestReport(id: number) {
  return request({
    url: `/archive-detection-job/report/${id}`,
    method: 'get'
  });
}
/* 保存目录附件 */
export interface ISaveItemFilesParams {
  id: number;
  itemAtt: AttItemsList;
}
export function saveItemFiles(data: ISaveItemFilesParams) {
  return request({
    url: `/archive-detection-job/save/items-att/`,
    method: 'post',
    data
  });
}
/* 保存原文附件 */
export interface ISaveOriginFilesParams {
  id: number;
  originalAtt: AttOriginal;
}
export function saveOriginFiles(data: ISaveOriginFilesParams) {
  return request({
    url: `/archive-detection-job/save/original-att/`,
    method: 'post',
    data
  });
}
// 开始检测任务
export function StartDetectionTask(id: number) {
  return request({
    url: `/archive-detection-job/start/${id}`,
    method: 'get'
  });
}
/* 通过id查找 */
export function findStandardizedDetectionById(id: number) {
  return request({
    url: `/archive-detection-job/${id}`,
    method: 'get'
  });
}
// 通过id删除检测任务
export function deleteStandardizedDetectionList(id: number | string) {
  return request({
    url: `/archive-detection-job/${id}`,
    method: 'delete'
  });
}
